<div ng-controller="OrderSearchCtrl as vm">
  <h1 class="page-title">搜索运单</h1>
  <div class="well">
    <form method='POST' action='/api/order/export'>
      <div class="form-horizontal">
        <fieldset>
          <div>
            <div class="span6">
              <div class="control-group" ng-if="vm.userRole=='admin'">
                <label class="control-label">选择发布企业会员</label>
                <div class="controls">
                  <select class="input-large" name="shipperId" ng-model="vm.order.shipperId">
                    <option value="0">全部</option>
                    <option ng-repeat="option in shippers" value="{{option.id}}">{{option.enterpriseName}}</option>
                  </select>
                  <p class="help-block"></p>
                </div>
              </div>
              <input type="hidden" ng-if="vm.userRole=='shipper'" value="{{vm.userId}}" name="shipperId" />
              <input type="hidden" ng-if="vm.userRole=='carrier'" value="0" name="shipperId" />
              <div class="control-group">
                <!-- Text input-->
                <label class="control-label">运单号</label>
                <div class="controls">
                  <input type="text" name="orderId" ng-model="vm.order.orderId"  class="input-large search-query">
                  <p class="help-block"></p>
                </div>
              </div>
              <div class="control-group">
                <!-- Search input-->
                <label class="control-label">发货号</label>
                <div class="controls">
                  <input type="text" name="dispatchId" ng-model="vm.order.dispatchId" class="input-large search-query">
                  <p class="help-block"></p>
                </div>
              </div>
              <div class="control-group">
                <!-- Select Basic -->
                <label class="control-label">始发城市</label>
                <div class="controls">
                  <input type="text" name="fromCity" ng-model="vm.order.fromCity" class="input-large search-query" >
                  <p class="help-block"></p>
                </div>
              </div>
              <div class="control-group">
                <!-- Select Basic -->
                <label class="control-label">车牌号</label>
                <div class="controls">
                  <input type="text" name="vehicleNumber" ng-model="vm.order.vehicleNumber" class="input-large search-query" >
                  <p class="help-block"></p>
                </div>
              </div>
            </div>
            <div class="span6">
              <div class="control-group">
                <!-- Select Basic -->
                <label class="control-label">到达城市</label>
                <div class="controls">
                  <input type="text" name="toCity" ng-model="vm.order.toCity" class="input-large search-query" >
                  <p class="help-block"></p>
                </div>
              </div>
              <div class="control-group">
                <!-- Select Basic -->
                <label class="control-label">支付</label>
                <div class="controls">
                  <select  ng-model="vm.paid">
                    <option value="0">全部</option>
                    <option value="1">已支付</option>
                    <option value="2">未支付</option>
                  </select>
                  <p class="help-block"></p>
                </div>
              </div>
              <div class="control-group">
                <!-- Select Basic -->
                <label class="control-label">状态</label>
                <div class="controls">
                  <select  ng-model="vm.status">
                    <option value="0">全部</option>
                    <option value="2">接单中</option>
                    <option value="3">已接单</option>
                    <option value="4">运送中</option>
                    <option value="5">已到达</option>
                    <option value="6">已交单</option>
                    <option value="7">申请发票</option>
                    <option value="8">已完成</option>
                  </select>
                  <p class="help-block"></p>
                </div>
              </div>
            </div>
          </div>
        </fieldset>
        <fieldset>
          <div class="control-group">
            <!-- Text input-->
            <label class="control-label">搜索起始日期</label>
            <div class="controls">
              <input id="startDate" placeholder="搜索起始日期" class="laydate-icon" onclick="laydate()" >
              <p class="help-block"></p>
            </div>
          </div>
          <div class="control-group">
            <!-- Search input-->
            <label class="control-label">搜索结束日期</label>
            <div class="controls">
              <input id="endDate" placeholder="搜索结束日期" class="laydate-icon" onclick="laydate()" >
              <p class="help-block"></p>
            </div>
          </div>
        </fieldset>
        <div class="control-group">
          <label class="control-label"></label>
          <!-- Button -->
          <div class="controls">
            <a class="btn btn-primary" ng-click="vm.searchOrder()">搜索</a>
          </div>
        </div>
      </div>
      <p ng-show="vm.noRecord">没有找到符合条件的运单！</p>

        <div class="table-responsive" ng-show="vm.orders.length>0">
          <input name="status" ng-value="vm.status!=0? vm.status:''" hidden/>
        <input name="paid" ng-value="vm.paid!=0? vm.paid:''" hidden/>
        <button class="btn" type="submit">导出结果</button>
        </form>
          <table class="table table-striped table-bordered">
            <thead>
              <tr>
                <th>单号</th>
                <th>发布企业</th>
                <th>状态</th>
                <th>始发城市</th>
                <th>到达城市</th>
                <th>司机</th>
                <th>车辆</th>
                <th>发布日期</th>
                <th>#</th>
              </tr>
            </thead>
            <tbody>
              <tr ng-repeat="order in vm.orders">
                <td><a ng-click="vm.viewDetail(order.id)" >{{order.orderId}}</a></td>
                <td>{{order.shipper.enterpriseName}}</td>
                <td ng-switch='order.status'>
                  <div ng-switch-when="1">未发布</div>
                  <div ng-switch-when="2">接单中</div>
                  <div ng-switch-when="3">已接单</div>
                  <div ng-switch-when="4">行驶中</div>
                  <div ng-switch-when="5">已到达</div>
                  <div ng-switch-when="6">已交单</div>
                  <div ng-switch-when="7">开票中</div>
                  <div ng-switch-when="8">已完成</div>
                </td>
                <td>{{order.fromCity}}</td>
                <td>{{order.toCity}}</td>
                <td>{{order.driver.name}}</td>
                <td>{{order.vehicle.vehicleNumber}}</td>
                <td>{{order.createTime| date:"yyyy-MM-dd"}}</td>
                <td>
                  <a class="btn btn-primary btn-mini" ng-click="vm.viewDetail(order.id)">查看</a>
                  <a class="btn btn-mini" ng-show="order.status==2 && (vm.userRole!='shipper' || (vm.userRole == 'shipper' && vm.shipperType == 1 && order.shipper.id==vm.userId))" ng-click="vm.sendIntention(order.id)">发起意向</a>
                  <a ng-click="vm.confirm(order.id)" class="btn btn-mini btn-danger" ng-show="vm.userRole!='carrier' && order.status==5 && vm.userRole!='revenuer'">确认交单</a>
                  <a ng-show="order.status==6 && vm.userRole!='carrier' && vm.userRole!='revenuer'" ng-click="vm.applyFapiao(order.id)" class="btn btn-mini">申请开票</a>
                  <a ng-show="order.status>3" id="map_{{order.orderId}}_{{order.vehicle.id}}" onclick='openWindow(this.id)'  class="btn btn-mini btn-info">查看地图</a>
                    <a ng-show="order.status>3" ng-href="/api/location/export/order/{{order.orderId}}"  class="btn btn-mini btn-info">导出数据</a>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
        <div class="pagination pagination-centered">
          <ul>
            <li ng-class="vm.firstPage? 'disabled':''" ng-switch="vm.firstPage">
              <a ng-switch-when="false" ng-click="vm.loadPage(vm.currentPage-1)" >&laquo;</a>
              <a ng-switch-when="true" >&laquo;</a>
            </li>
            <li ng-repeat="me in vm.pages" ng-class="me==vm.currentPage? 'active':''" ng-switch="me==vm.currentPage">
              <a ng-switch-when="false" ng-click="vm.loadPage(me)" >{{me}}</a>
              <a ng-switch-when="true" >{{me}}</a>
            </li>
            <li ng-class="vm.lastPage? 'disabled':''" ng-switch on="vm.lastPage">
              <a ng-switch-when="false" ng-click="vm.loadPage(vm.currentPage+1)">&raquo;</a>
              <a ng-switch-when="true" >&raquo;</a>
            </li>
          </ul>
        </div>
    </div>
  </div>
</div>
<script>
function openWindow(oid)
{
oid = oid.replace("map_","");
var ids = oid.split("_");
var orderId = ids[0];
var vehicleId = ids[1];
var url = "../views/map/map.html?id="+ orderId + "&vid="+vehicleId;
var child = window.open(url ,"运单路线","width=800,height=600,toolbar=no,scrollbars=no,menubar=no,screenX=100,screenY=50");
}
</script>